package com.openflag.bwicservice.service.impl;

import com.openflag.bwicservice.domain.Client;
import com.openflag.bwicservice.domain.LoginRequest;
import com.openflag.bwicservice.domain.RegisterRequest;
import com.openflag.bwicservice.domain.Result;
import com.openflag.bwicservice.service.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

import java.util.Optional;

@Service
public class LoginServiceImpl implements LoginService {


    @Autowired
    private RestTemplate restTemplate;

    @Override
    public Client getClient(Long clientId){


        Client client = restTemplate.getForObject("http://localhost:8087/getClient/{id}",Client.class,clientId);


        return client;
    }
    @Override
    public Optional<Client> login(LoginRequest loginRequest){

        Optional<Client> optionalClient = restTemplate.postForObject("http://localhost:8087/login",loginRequest,Optional.class);

        return optionalClient;

    }

    @Override
    public Integer register(RegisterRequest registerRequest){

        Integer status = restTemplate.postForObject("http://localhost:8087/register",registerRequest, Integer.class);



        return status;
    }
}
